﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using iTravel.Data;

namespace iTravel.Repository
{
    public abstract class Repository<T> : IRepository<T>
        where T : class
    {
        private readonly TravelContext _context;
        // TODO : Still have to find a mechanism to manage the lifetime of our context.

        public Repository()
        {
            _context = new TravelContext();
        }

        public IEnumerable<T> All()
        {
            return _context.Set<T>().ToList();
        }

        public T Find(int id)
        {
            throw new NotImplementedException();
        }

        public T Find(int id, params Expression<Func<T, object>>[] includeProperties)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<T> AllIncluding(params Expression<Func<T, object>>[] includeProperties)
        {
            throw new NotImplementedException();
        }

        public void InsertOrUpdate(T entity)
        {
            throw new NotImplementedException();
        }

        public void Delete(int id)
        {
            throw new NotImplementedException();
        }

        public void Delete(T entity)
        {
            DbSet<T> dbSet = _context.Set<T>();
            dbSet.Remove(entity);
            _context.SaveChanges();
        }
    }
}